<template>
  <div>
    <el-form :inline="true" class="el-form">
      <template>
        <el-form-item label="题库分类">
          <div class="block">
            <span class="demonstration"></span>
            <el-cascader
              :props="{
                value: 'id',
                label: 'name',
                children: 'child',
                emitPath: false,
              }"
              v-model="values"
              :options="fen"
              @change="handleChange"
            ></el-cascader>
          </div>
        </el-form-item>
      </template>
      <el-form-item label="题库名称">
        <el-input
          v-model="input"
          placeholder="请输入题库名称关键字"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="el-icon-search" @click="sou">搜索</el-button>
        <el-button class="el-icon-refresh-left" @click="chong">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格数据渲染 -->
    <el-table
      border
      :data="list"
      style="width: 63.2%"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="name" label="题库名称" width="180">
      </el-table-column>
      <el-table-column prop="classify" label="所属分类" width="160">
      </el-table-column>
      <el-table-column
        prop="ques_amount"
        label="题目数"
        width="120"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="creator"
        label="创建人"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column label="更新时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>
            {{ scope.row.updated_at | filtime }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120" show-overflow-tooltip>
        <template>
          <el-button type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[2, 3, 5]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="35"
    >
    </el-pagination>
  </div>
</template>
<script>
import { guan, fens } from "../../api/api";
export default {
  components: {},
  data() {
    return {
      input: "",
      list: [],
      fen: [],
      values: [],
      page: 1,
      limit: 5,
    };
  },
  mounted() {
    this.feng();
    fens({
      classify: this.values,
    }).then((res) => {
      this.fen = res.data.data;
    });
  },
  // 时间的过滤
  filters: {
    filtime(val) {
      return new Date(val * 1000).toLocaleString();
    },
  },
  methods: {
    // 封装函数
    feng() {
      guan({
        page: this.page,
        limit: this.limit,
        classify: this.values,
        name: this.input,
      }).then((res) => {
        this.list = res.data.data.list;
      });
    },
    // 搜索
    sou() {
      this.feng();
    },
    // 重置
    chong() {
    this.values = "";
     this.input = "";
      this.feng();
    },
    handleChange(val) {
      this.values = val;
    },
    // 每页分多少条
    handleSizeChange(size) {
      this.limit = size;
      this.feng();
    },
    // 点击页面分页
    handleCurrentChange(Current) {
      this.page = Current;
      this.feng();
    },
  },
  computed: {
  },
  watch: {},
};
</script>
<style scoped>
.el-form {
  float: left;
  margin-top: 20px;
}
</style>
